//
//  TopView.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/5/31.
//

#import "TopView.h"
#import "CommonUtil.h"

@interface TopView()
@property (strong, nonatomic) UIImageView *iconImageView;
@property (strong, nonatomic) UIButton *followBtn;
@property (strong, nonatomic) UILabel *nameLabel;
@property (strong, nonatomic) UILabel *levelLabel;
@property (strong, nonatomic) UILabel *timeLabel;
@property (strong, nonatomic) UIButton *shangBtn;
@property (strong, nonatomic) UIButton *historyBtn;
@end

@implementation TopView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.iconImageView];
        [self addSubview:self.followBtn];
        [self addSubview:self.nameLabel];
        [self addSubview:self.levelLabel];
        [self addSubview:self.timeLabel];
        [self addSubview:self.shangBtn];
        [self addSubview:self.historyBtn];
    }
    return self;
}



- (void)followBtnClick:(UIButton *)sender{
    sender.selected = !sender.selected;
    if (sender.selected) {
        [sender setTitle:@"取消关注" forState:UIControlStateNormal];
        sender.backgroundColor = [UIColor lightGrayColor];
    }else{
        [sender setTitle:@"+关注" forState:UIControlStateNormal];
        sender.backgroundColor = RGB(255.0, 90.0, 117.0);
    }
}
- (void)shangBtnClick:(UIButton *)sender{
    
}

- (void)historyBtnClick:(UIButton *)sender{
    
}
#pragma mark - lazy
-(UIImageView *)iconImageView{
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(AD(20),AD(10), AD(50), AD(50))];
        _iconImageView.image = [UIImage imageNamed:@"defaultIcon.jpeg"];
        _iconImageView.layer.cornerRadius = AD(25);
        _iconImageView.clipsToBounds = YES;
    }
    return _iconImageView;
}

-(UIButton *)followBtn{
    if (!_followBtn) {
        _followBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_followBtn setTitle:@"+关注" forState:UIControlStateNormal];
        _followBtn.backgroundColor = RGB(255.0, 90.0, 117.0);
        [_followBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_followBtn addTarget:self action:@selector(followBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _followBtn.layer.cornerRadius = AD(5);
        _followBtn.clipsToBounds = YES;
        
        _followBtn.frame = CGRectMake(AD(20), AD(45), AD(50), AD(20));
        _followBtn.titleLabel.font = [UIFont systemFontOfSize:AD(11)];
    }
    return _followBtn;
}


-(UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_iconImageView.right + AD(10), AD(10), AD(100), AD(25))];
        _nameLabel.font = [UIFont systemFontOfSize:AD(14)];
        _nameLabel.textColor = [UIColor blackColor];
        _nameLabel.text = @"天天向上";
    }
    return _nameLabel;
}

-(UILabel *)levelLabel{
    if (!_levelLabel) {
        _levelLabel = [[UILabel alloc] initWithFrame:CGRectMake(_nameLabel.left, _nameLabel.bottom + AD(5), AD(20), AD(15))];
        _levelLabel.font = [UIFont systemFontOfSize:AD(10)];
        _levelLabel.textColor = [UIColor whiteColor];
        _levelLabel.backgroundColor = RGB(156.0, 168.0, 168.0);
        _levelLabel.layer.cornerRadius = AD(2);
        _levelLabel.clipsToBounds = YES;
        _levelLabel.textAlignment = NSTextAlignmentCenter;
        _levelLabel.text = @"Lv3";
    }
    return _levelLabel;
}


-(UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(_levelLabel.right + AD(5), _nameLabel.bottom, AD(200), AD(25))];
        _timeLabel.font = [UIFont systemFontOfSize:AD(12)];
        _timeLabel.textColor = [UIColor lightGrayColor];
        _timeLabel.text = @"楼主1小时前";
    }
    return _timeLabel;
}

-(UIButton *)shangBtn{
    if (!_shangBtn) {
        _shangBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_shangBtn setBackgroundImage:[UIImage imageNamed:@"icon_shang"] forState:UIControlStateNormal];
        [_shangBtn addTarget:self action:@selector(shangBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _shangBtn.frame = CGRectMake(AD(250), 0, AD(25), AD(25));
        _shangBtn.centerY = self.height/2;
    }
    return _shangBtn;
}

-(UIButton *)historyBtn{
    if (!_historyBtn) {
        _historyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_historyBtn setTitle:@"历史帖子" forState:UIControlStateNormal];
        _historyBtn.backgroundColor = RGB(255.0, 90.0, 117.0);
        [_historyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_historyBtn addTarget:self action:@selector(historyBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _historyBtn.layer.cornerRadius = AD(5);
        _historyBtn.clipsToBounds = YES;
        _historyBtn.frame = CGRectMake(_shangBtn.right + AD(15), 0, AD(70), AD(25));
        _historyBtn.titleLabel.font = [UIFont systemFontOfSize:AD(13)];
        _historyBtn.centerY = self.height/2;
    }
    return _historyBtn;
}



@end
